package aiku.numericalcontroloa.Controller.Products;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.ProductsDto;
import aiku.numericalcontroloa.Model.Dto.PurchaseOrdersDto;
import aiku.numericalcontroloa.Model.Entity.Products;
import aiku.numericalcontroloa.Model.Vo.PurchaseInfoVo;
import aiku.numericalcontroloa.Service.Impl.ProductsServiceImpl;
import aiku.numericalcontroloa.Service.ProductsService;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * @author 马文杰
 * @version 1.0
 */
@RestController
@RequestMapping("/products")
public class ProductsController {
    @Autowired
    private ProductsService productsService;


//    /**
//     *     库管新增产品
//     */
//    @RequestMapping("/apply")
//    //添加事务
//    @Transactional
//    public Result apply(@RequestBody ProductsDto productsDto) {
//        Result result =  productsService.apply(productsDto);
//        return  result;
//    }

    /**
     * 员工查询申请采购订单信息，分页查询
     */
    @PostMapping("/purchaseInfoList")
    public Result purchaseList(@RequestParam("page") Integer page, @RequestParam("size") Integer size) {
        //TODO 查询入库账单列表
        Result  result = productsService.purchaseList(page,size);
        return result;
    }

    /**
     * 员工通过模糊查询采购订单信息,
     * 订单号,产品名称,型号,采购人来查询
     */
    @PostMapping("/purchaseInfo")
    public Result purchaseInfo(@RequestParam("name") String name) {
        //TODO 查询入库账单列表
        Result  result = productsService.purchaseReceiptsInfo(name);
        return result;
    }


    /**
     * 员工查询入库订单信息
     */
    @PostMapping("/purchaseReceiptsInfoList")
    public Result purchaseList(@RequestParam("page") Integer page, @RequestParam("size") Integer size,@RequestParam("receiptsStatus") String receiptsStatus) {
        //TODO 查询入库账单列表
        Result  result = productsService.purchaseReceiptsInfoList(page,size,receiptsStatus);
        return result;
    }

    /**
     * 员工通过模糊查询入库订单信息,通过名称,型号,采购人来查询
     */
    @PostMapping("/purchaseReceiptsInfos")
    public Result purchaseReceiptsInfos(@RequestParam("name") String name) {
        //TODO 查询入库账单列表
        Result  result = productsService.purchaseReceiptsInfos(name);
        return result;
    }


    /**
     * 管理员修改入库订单信息
     */
    @PostMapping("/updateReceiptsInfo")
    public Result updateReceiptsInfo(@RequestBody PurchaseInfoVo purchaseInfoVo) {
        Result  result = productsService.updateReceiptsInfo(purchaseInfoVo);
        return result;
    }

    /**
     * 新增采购订单
     * @param purchaseOrdersDto
     * @return
     */
    @PostMapping("/addPurchaseOrders")
    public Result addPurchaseOrders(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.addPurchaseOrders(purchaseOrdersDto);
    }

    /**
     * 查询采购订单列表
     * @param purchaseOrdersDto
     * @return
     */
    @PostMapping("/getPurchaseOrdersList")
    public Result getPurchaseOrdersList(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.getPurchaseOrdersList(purchaseOrdersDto);
    }

    /**
     * 获取单个采购订单
     * @param purchaseOrdersDto
     * @return
     */
    @PostMapping("/getPurchaseOrders")
    public Result getPurchaseOrders(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.getPurchaseOrders(purchaseOrdersDto);
    }

    /**
     * 修改采购订单
     * @param purchaseOrdersDto
     * @return
     */
    @PostMapping("/updatePurchaseOrders")
    public Result updatePurchaseOrders(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.updatePurchaseOrders(purchaseOrdersDto);
    }

    /**
     * 审核订单
     * @param purchaseOrdersDto
     * @return
     */
    @PostMapping("/applyPurchaseOrders")
    public Result applyPurchaseOrders(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.applyPurchaseOrders(purchaseOrdersDto);
    }

    /**
     * 一键入库
     * @param purchaseOrdersDto
     * @return
     */
    @PostMapping("/oneKeyPurchaseOrders")
    public Result oneKeyPurchaseOrders(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.oneKeyPurchaseOrders(purchaseOrdersDto);
    }

    @PostMapping("/deletePurchasing")
    public Result deletePurchasing(@RequestBody PurchaseOrdersDto purchaseOrdersDto){
        return productsService.deletePurchasing(purchaseOrdersDto);
    }
}
